package com.supply.dl.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import butterknife.BindView;
import com.supply.dl.R;
import com.supply.dl.bean.WorkNotesBean;

import java.util.ArrayList;

public class WorkNotesActivity extends BaseActivity
{
	/**
	 * 作业记录数据源
	 */
	private ArrayList<WorkNotesBean> workNotesBeans = new ArrayList<>();
	private WorkNotesAdapter workNotesAdapter;
	@BindView(R.id.layout_work_root) ListView workList;
	@BindView(R.id.txt_add_new_work) TextView txtAdd;
	@BindView(R.id.txt_confirm) TextView txtConfirm;

	@Override protected int getLayoutResource()
	{
		return R.layout.activity_work_notes_layout;
	}

	@Override protected void onCreate(@Nullable Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setTitleShow("作业记录");
		txtAdd.setOnClickListener(this);
		txtConfirm.setOnClickListener(this);
		workNotesAdapter = new WorkNotesAdapter(this, workNotesBeans);
		workList.setAdapter(workNotesAdapter);
	}

//	/**
//	 * 构建子作业记录
//	 */
//	private void createNoteItem()
//	{
//		View workItem = LayoutInflater.from(this).inflate(R.layout.layout_work_notes, null);
//		TextView txtFactroyName = (TextView) workItem.findViewById(R.id.txt_work_factroy);
//		TextView txtWorkMan = workItem.findViewById(R.id.txt_work_man);
//		TextView txtModel = workItem.findViewById(R.id.txt_work_model);
//		TextView txtRate = workItem.findViewById(R.id.txt_work_rate);
//		TextView txtNumJ = workItem.findViewById(R.id.txt_work_num_jian);
//		TextView txtNumD = workItem.findViewById(R.id.txt_work_num_dun);
//	}

	@Override public void onClick(View v)
	{
		super.onClick(v);
		if (v == txtAdd)
		{
			WorkNotesBean workNotesBean = new WorkNotesBean();
			workNotesBeans.add(workNotesBean);
			workNotesAdapter.notifyDataSetChanged();
		}
		else if (v == txtConfirm)
		{

		}
	}

	class WorkNotesAdapter extends BaseAdapter
	{
		private Context mContext;
		private ArrayList<WorkNotesBean> beans = new ArrayList<WorkNotesBean>();

		public WorkNotesAdapter(Context context, ArrayList<WorkNotesBean> workNotesBeans)
		{
			this.mContext = context;
			this.beans = workNotesBeans;
		}

		@Override public int getCount()
		{
			return beans.size();
		}

		@Override public Object getItem(int position)
		{
			return beans.get(position);
		}

		@Override public long getItemId(int position)
		{
			return position;
		}

		@Override public View getView(int position, View convertView, ViewGroup parent)
		{
			ViewHolder viewHolder = null;
			if (convertView == null)
			{
				viewHolder = new ViewHolder();
				convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_work_notes, null);
				viewHolder.txtFactroyName = convertView.findViewById(R.id.txt_work_factroy);
				viewHolder.txtWorkMan = convertView.findViewById(R.id.txt_work_man);
				viewHolder.txtModel = convertView.findViewById(R.id.txt_work_model);
				viewHolder.txtRate = convertView.findViewById(R.id.txt_work_rate);
				viewHolder.txtNumJ = convertView.findViewById(R.id.txt_work_num_jian);
				viewHolder.txtNumD = convertView.findViewById(R.id.txt_work_num_dun);
				convertView.setTag(viewHolder);
			}
			else
			{
				viewHolder = (ViewHolder) convertView.getTag();
			}
			viewHolder.txtFactroyName.setOnClickListener(new View.OnClickListener()
			{
				@Override public void onClick(View v)
				{

				}
			});

			return convertView;
		}

		class ViewHolder
		{
			TextView txtFactroyName;
			TextView txtWorkMan;
			TextView txtModel;
			TextView txtRate;
			TextView txtNumJ;
			TextView txtNumD;
		}
	}
}
